gh-139398: Add supported sunder names to Enum __dir__ for REPL completions#139985
Open
RafaelWO wants to merge 3 commits intopython:mainfrom
Open
gh-139398: Add supported sunder names to Enum __dir__ for REPL completions#139985RafaelWO wants to merge 3 commits intopython:mainfrom
__dir__ for REPL completions#139985RafaelWO wants to merge 3 commits intopython:mainfrom
Conversation
RafaelWO
commented
Oct 12, 2025
Comment on lines
+5152
to
+5155
| Attribute(name='_missing_', kind='class method', | ||
| defining_class=Enum, object=self.Color._missing_), | ||
| Attribute(name='_generate_next_value_', kind='static method', | ||
| defining_class=self.Color, object=staticmethod(self.Color._generate_next_value_)), |
Contributor
Author
There was a problem hiding this comment.
I tried to adjust this test to expect the new attributes, but I wasn't able to get the test to pass. I guess I need some help here 🙂 thanks!
./python -m unittest -v test.test_enum.TestStdLib.test_inspect_classify_class_attrs
Contributor
Author
There was a problem hiding this comment.
@ethanfurman do you think you can help me to fix this test? Thanks in advance!
Misc/NEWS.d/next/Library/2025-10-12-08-46-26.gh-issue-139398.hESOMl.rst
Outdated
Show resolved
Hide resolved
This change adds the sunder names `_generate_next_value_` and `_missing_` to the `__dir__` method of `EnumType` and `Enum`. In Addition, The instance level sunder names `_add_alias_` and `_add_value_alias_` are added to `Enum.__dir__`. With the sunder names exposed in the `dir()` method, the REPL autocomplete will also show them. Co-Authored-By: SimonGPrs <107691772+SimonGPrs@users.noreply.github.com>
This change highlights which of the attributes were expected versus were actually there.
bafd9e3 to
0d9fedf
Compare
Member
|
Please don't force push, it complicates reviewing. All commits are squashed at the end anyway. |
Misc/NEWS.d/next/Library/2025-10-12-08-46-26.gh-issue-139398.hESOMl.rst
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change adds the sunder names
_generate_next_value_and_missing_to the__dir__method ofEnumTypeandEnum.In Addition, The instance level sunder names
_add_alias_and_add_value_alias_are added toEnum.__dir__.With the sunder names exposed in the
dir()method, the REPL autocomplete will also show them.Note: This PR is based on the first attempt to address this issue: #139418
Preview:
📚 Documentation preview 📚: https://cpython-previews--139985.org.readthedocs.build/